home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMIBEST1.ADF / AmigaBasicStuff / HouseHold / HHInv.DOC < prev    next >
Text File  |  1987-07-22  |  24KB  |  427 lines

  1.  
  2. The Household Inventory System 
  3. By Brian Catley
  4.  
  5.     The Household Inventory System is a collection of three inter-related
  6. Amiga Basic programs which provide the means of maintaining an inventory
  7. of household possessions, along with the capability of updating that
  8. inventory and printing inventory reports in a number of possible
  9. sequences.  Program #1 is the main program which provides for the entry and
  10. maintenance of inventory items, while Program #2 allows reports in any of
  11. three sequences, and Program #3 is a file maintenance program which is used
  12. to maintain the actual files of data; (as against the data itself).  All
  13. three programs provide ample online help facilities.
  14.  
  15.     A little more specifically, Program #1 allows for the entry of
  16. individual items; browsing through the file of data; and selecting any
  17. record for modification or deletion.  When deleted,  a record is tagged as
  18. such but is actually still available, (and may be restored), until the file
  19. is reorganized.  Program #2 prints inventory reports in entry, room, or
  20. item sequence, and Program #3 provides a number of file maintenance options
  21. such as reorganization, displaying the count of records in the file,
  22. initialization, etc.
  23.  
  24.     Program #1 uses just about all of the memory available to Basic
  25. programs which explains why the other two functions were not included in
  26. that program! Further, since a second program was needed (at least), why
  27. not separate the major functions into distinct programs?  Hence, there are
  28. three of them!
  29.  
  30.     Entering the Three Programs
  31.  
  32.     Should you choose to enter the three programs from the reproduced 
  33. listings accompanying this article, there are a couple of things you should
  34. note.  (Please be aware these three programs are also available on an 
  35. Amicus disk should you prefer not to type in the rather lengthy listings. 
  36. See elsewhere in this magazine for more information regarding Amicus 
  37. disks).
  38.  
  39.     Anyway, there are a number of subprograms which are common to all three
  40. programs and there is simply no need to enter them all for each program. 
  41. So, before you get into entering the three main programs, enter Listing
  42. #1.  This listing is composed of the common subprograms, and when you have
  43. finished entering it, be sure and save it with the "A" option. 
  44.  
  45.     For example, SAVE "subs",A.  The "A" option causes the entered
  46. subprograms to be saved in an ASCII format which will subsequently allow
  47. them to be MERGEd with the other three programs when they are entered. Note
  48. that you must enter an immediate SAVE command to accomplish this.  The SAVE
  49. and SAVE AS menu items do not allow the use of this option.
  50.     
  51.     Once you have successfully entered this listing, proceed with Listings 
  52. #2, #3, and #4.  These three listing are the main portions of the three 
  53. programs under discussion.  When each has been entered, click in the Output
  54. window and enter the immediate command MERGE "subs", and then save the 
  55. merged programs with an appropriate name.  How about HInvMain, HInvPrint, 
  56. and HInvMaint?
  57.  
  58.     If you receive an error message after entering the merge command, the
  59. chances are you forgot to save "subs" with the "A" option.  This is no
  60. great problem.  Just save what you have been working on, load "subs" (or
  61. whatever you called it), re-save it with the "A" option, load what you were
  62. working on previously, and issue the merge command again.  When each of the
  63. programs has been completed, be sure to save it before you try to RUN (or
  64. execute) it.
  65.  
  66.     One thing you must be aware of is that memory really is tight (if you
  67. have a 512K machine) with the main program.  If you have been doing a lot
  68. of editing of other programs, it is quite probable there will not be enough
  69. memory available for the program to execute successfully.  Therefore, if
  70. you receive an "out of memory" message, you should not presume there is an
  71. error with the program.  However, you will probably find that you have to
  72. reboot the machine in order to get the program to run correctly. For better
  73. or worse, this is the only way to free some of the memory that is allocated
  74. during a number of functions (such as cut and paste), and is never freed
  75. (presumably to save having to load it again).
  76.  
  77.     Anyway, once all three programs have been entered and saved, you are 
  78. ready to start using them.
  79.  
  80.     Using the Household Inventory System
  81.  
  82.     Before we get into the whys and wherefores, a couple of general
  83. comments are in order.  The major purpose of any system such as this is to
  84. keep a record of your household inventory for insurance purposes in case of
  85. burglaries, fire, etc.  This being the case, it does not make a lot of 
  86. sense to keep that record in the house itself!  We strongly recommend that
  87. you keep this record on a separate disk, and that you keep a copy of that
  88. disk in a safe-deposit box, or somewhere equally safe.  Once you have
  89. initially created your inventory file, you will probably find it 
  90. appropriate to update that file once or twice a year, replacing the disk in
  91. the safe deposit box at the same time.
  92.  
  93.     To create this separate disk, simply initialize (or Format) the disk 
  94. you wish to use, and copy Amiga Basic and the three programs onto it. If
  95. you wish, use this disk in place of your normal Basic disk to enter the
  96. programs originally.  In fact, this is a good idea because it keeps 
  97. everything separate right from the start.  Don't forget to make backup 
  98. copies of this disk along with the copy you will be placing in the
  99. safe-deposit box!
  100.  
  101.     You will find the programs easy to use.  All have help menus which are
  102. available at all times, and which should be read in their entirety the
  103. first time each program is used.  Beyond this, other menus and various 
  104. gadgets provide a very straightforward working environment.  Let's take a
  105. look at each of the three programs so you will know what to expect when you
  106. actually use them.
  107.  
  108.     The Data Entry and Maintenance Program:
  109.  
  110.     This is the main, and largest, of the three programs.  Its purpose is
  111. to provide you with the means of entering new inventory items, and updating
  112. (changing and/or deleting) items you have previously entered. In doing
  113. this, it makes extensive use of many of the Amiga's special features and
  114. follows what is emerging as the "standard" Amiga user interface. The result
  115. is that a lot of memory is used!  In fact, you will need at least   512K of
  116. memory, and even then things will be a little tight.  What this means is
  117. that you will probably be unable to have any other task, such as a clock,
  118. running in the background, and if you have previously used some Amiga
  119. functions which load disk based routines in to memory (such as speech, cut
  120. and paste, etc) you may even find you have to reboot the machine.  Some
  121. memory usage notes follow:
  122.  
  123.     -the default Basic program memory allocation of 25000 is just, and only
  124. just, sufficient to hold the program.
  125.  
  126.     -the first thing the program does is to give itself some more memory 
  127. for the arrays it will dimension.  This, in turn, reduces the amount of 
  128. system heap space available for the high resolution screens and windows, 
  129. and the file buffers.
  130.  
  131.     -The actual amount of memory required depends on the number of records 
  132. in the inventory file.  By adjusting the SIZE command at the beginning you
  133. may increase or decrease the size of the program space as it becomes 
  134. appropriate.  Remember, as the program space increases, the heap space 
  135. decreases, and vice versa.
  136.  
  137.     When you run the program, you will be presented with a title screen, 
  138. and a request to enter the date.  Should you press the right mouse button 
  139. you will also see you have three menus available to you: Project, Help, and
  140. Data Files.
  141.  
  142.     If this is the first time you have used the programs, you should do as
  143. the screen suggests and read all the Help menu items; you may also want to
  144. select Initialize under the Data File menu to create your inventory file. 
  145. Should you not do the latter yourself, and no inventory file exists, the
  146. program will create one for you automatically a little later.  Normally, 
  147. this will only happen once but it does provide you with the means of
  148. starting over should you ever wish to.
  149.  
  150.     While on the subject, let's take a closer look at the Project and Data
  151. File menus; (the Help menu is self explanatory).  The Project menu has a
  152. single item: Quit.  And it does just that, terminating the program and
  153. returning control to Basic.  The Data File menu has the following items:
  154.  
  155.     Initialize.  A new and empty inventory file established.  If a file 
  156. presently exists, you will be asked if it is OK to delete it before the new
  157. one is created.
  158.  
  159.     Update Count.  The program keeps track of the number of records in the
  160. inventory file by means of a single record "count" file.  When adding 
  161. records to the file, this count file is NOT updated with every single 
  162. addition; instead, an internal counter keeps track of the number of records
  163. being added, and the "count" file is only updated when you select a new 
  164. function or quit the program.  The purpose of this menu item is to allow 
  165. you to force the "count" file to be updated from time to time when adding a
  166. substantial number of new records.  This provides a degree of protection in
  167. case of a power failure, system crash, etc.
  168.  
  169.     No. of Records.  This item simply provides you with the current count 
  170. of committed and and non-committed records.  To commit the non-committed 
  171. records, use the Update Count item described just above.
  172.  
  173.     Well, it's now time to enter the date as requested.  The request is to
  174. enter it in form mm/dd/yy (e.g. 09/01/87 for Jan 9, 1987), however what is
  175. actually entered is not edited, but is simply used to identify when records
  176. in the file have been added and/or updated.  So you may really enter
  177. whatever you wish, except for a null value.  Once the date has been 
  178. accepted, three gadgets will appear on the screen and you are into the meat
  179. of the program.  The three gadgets are:
  180.  
  181.     Add:  Selecting this gadget will allow you to add new inventory items 
  182. to the existing file.  Once selected, an "Add a New Item" window will open,
  183. and you will be prompted for the name of the item; the room the item
  184. belongs in; the date of purchase; its original cost; its current worth; its
  185. replacement cost; its serial number; and any comments you may wish to
  186. include.  Note that only the first two items are required, the remainder
  187. may be left blank or updated at a later time.  While entering information,
  188. you may select from Cancel, OK, and Modify gadgets at any time.
  189.  
  190.     Cancel does just that.  The current item is forgotten, and you are 
  191. asked if you wish to enter another item, or if you wish to Quit.
  192.  
  193.     OK accepts the item you have entered and adds it to the inventory 
  194. file.
  195.  
  196.     Modify allows you to update the item you are entering before adding it
  197. to the file; (should you enter an incorrect piece of information, for 
  198. example).  Once selected, you will be presented with a window which
  199. displays each piece of information included with the record in question. 
  200. To update a piece of information, (correct or add), just click in that
  201. item's box and then edit the existing information or enter the new
  202. information. 
  203.  
  204. Once you have used any of the above three gadgets, you will then be given 
  205. a choice of another two: Add More and Quit.
  206.  
  207.     Add More.  This selection allows you to start entering a new item 
  208. into your inventory.
  209.  
  210.     Quit.  Selecting this item will cause the record count file to be 
  211. updated, (thereby committing all the records you have just entered), and 
  212. will subsequently return you to the title screen.
  213.  
  214.      Note that dates are not entered manually, nor are they updateable. 
  215.  Dates are handled automatically, using the date you entered when you first
  216.  initiated the program.
  217.  
  218.     Review:  Selecting this option will cause the entire inventory file to
  219. be read into memory.  Once this has been done, you will be presented with a
  220. full sized window which displays the first 18 records in the file, along
  221. with some further information about the file, a scroll bar on the right
  222. hand side of the screen, and a "Finished" gadget in the upper right 
  223. corner.  Selecting this latter gadget will return you to the title screen; 
  224. (the internal representation of the file is also erased).
  225.  
  226.     The scroll bar consists of upper and lower arrow-heads with a "bar" 
  227. between them.  Clicking on the arrow-heads will cause the display to move 
  228. up or down by a single record.  The "bar" is used to display the position
  229. of the 18 displayed records relative to the entire file.  The bar itself is
  230. colored blue, spans the space between the two arrow-heads, and represents
  231. the full file of inventory records.  The display of the 18 records on the
  232. screen is represented by a smaller white bar which is superimposed on the
  233. blue bar.  The size of this white bar is the same percentage of the blue
  234. bar as the 18 records are of the number of records in  the file.  Thus, if
  235. the file consists of 18 records or less, the white bar will cover the blue
  236. bar in its entirety; but, the more records there are in the file (over 18)
  237. the smaller in length the white bar will become.  So, by clicking in the
  238. blue portion of the bar, you may choose any set of 18 records from the file
  239. to display; (although you may have to fine tune with the arrow-heads).
  240.  
  241.     Now that you can browse through the file, what can you do with the 
  242. records?  Well, if you wish to do something (like modify or delete) with 
  243. one of the records on the screen, just click on it!
  244.  
  245.     You will receive a display of the record with each field contained 
  246. within a box.  There will also be three gadgets to choose from: Modify, OK,
  247. and Delete.  If you choose Modify, you will be requested to click in the
  248. field you wish to update, and you may then update that field.  When all is
  249. well, select the OK gadget. 
  250.  
  251.     Should you wish to discard the record, just click in the Delete gadget;
  252. you will then be asked if this is really what you want to do (just to be on
  253. the safe side), and if you select yes the record will be "logically" 
  254. removed from the file.  What this means is that the record is "marked" for
  255. deletion, rather than actually (physically) being deleted.  Subsequent 
  256. reviews of the inventory file will show deleted records with asterisks 
  257. between the fields of information.  If you click on one of these records, 
  258. you will be told the record has been deleted and requested if you wish to
  259. restore the record to the file.  Just select the Yes or No gadget! Note
  260. that logically deleted records will not be physically deleted from the file
  261. until it is reorganized; see a little later in the article for more
  262. information.
  263.  
  264.     Selecting OK will return you to the original display.  Please note that
  265. the "Review" display will always reflect the file as it existed when Review
  266. was originally selected; deletions or changes you may have made will not
  267. show up until the file is re-reviewed at a later time.
  268.  
  269.     Quit.  Selecting this gadget provides the same result as selecting the
  270. Project/Quit menu item: the program terminates and control is returned to
  271. Basic.
  272.  
  273.     The Print Reports Program:
  274.  
  275.     This program has no special memory requirements, is entirely menu 
  276. driven, will provide you with inventory reports in any of Entry, Room, or
  277. Item sequence, and will work with any printer supported by the Amiga.
  278.  
  279.     Once invoked, you will be presented with a title screen which is
  280. similar to that of The Data Entry and Maintenance Program; however, there
  281. will be no gadgets to select, you must use the three menus.
  282.  
  283.     The Project menu has a single Quit item which, when selected, will 
  284. terminate the program and return you to Basic.  The Help menu provides 
  285. information about the options available under the third menu, and should be
  286. read in its entirety before actually printing a report.  The final menu
  287. addresses the main purpose of the program and allows you to produce printed
  288. reports of your inventory in the sequence in which you entered them; in
  289. sequence by the room in which they reside; or in sequence by the items
  290. themselves.
  291.  
  292.     Probably the most important thing to note is that Order Entry reports 
  293. may only be produced before either of the other two reports are produced. 
  294. In fact, once a report in room or item sequence is requested, the Order 
  295. Entry option in made non-selectable.  (If the inventory array is sorted, as
  296. it must be for room or item sequence reports, it becomes impossible to
  297. return it to its original order entry sequence without reloading it from
  298. disk).
  299.  
  300.     It may also be appropriate (even if a little obvious) to mention that a
  301. printer must be attached to your Amiga in order to make effective use of
  302. this program.
  303.  
  304.     The File Maintenance Program:
  305.  
  306.     Like the report program described above, this program has no special 
  307. memory requirements, and is entirely menu driven.  Once again there are 
  308. three menus: The Project menu has a Quit item for terminating the program; 
  309. the Help menu provides information about using the third menu; while the 
  310. Maintenance menu itself provides a number of items designed to assist in
  311. maintaining the file of inventory items.  Note that this program is more
  312. concerned with maintaining the inventory file itself, rather than the data
  313. which is contained therein.
  314.  
  315.     Within the Maintenance menu, you will find the following items:
  316.  
  317.     Initialize:  This repeats the function available in The Data Entry and
  318. Maintenance Program.  It effectively deletes any existing file of inventory
  319. items and allows you to start from scratch, should you so desire.
  320.  
  321.     Reorganize:  This item will only be necessary after a number of records
  322. have been "logically" deleted from the inventory file,  and the time has 
  323. come to actually and physically remove them from the file.  This is done by
  324. copying the file and dropping the "logically" deleted records during the
  325. process.  Please note that once a file has been reorganized, it becomes 
  326. impossible to reclaim logically deleted records.
  327.  
  328.     Record Count: This an informational item which simply provides you with
  329. a count of the number of inventory records on file.
  330.  
  331.     Update Count:  This item will only be required if something out of the
  332. ordinary happens to your inventory file and it gets out of step with the
  333. count file.  The system uses this single record count file to keep track of
  334. the number of records in the inventory file.  As a general rule, this one
  335. record file will accurately reflect the number of inventory records being
  336. carried.  However, it is conceivable that the two could get out of step as
  337. the result of some unexpected event, (such as a power failure). Should this
  338. ever happen, just use this menu item to reset the count file.
  339.  
  340.     This program will probably not require a lot of use, but don't forget 
  341. you have it.  And if you do delete records from time  to time, please don't
  342. forget to reorganize the file occasionally!
  343.  
  344.     Programming Notes
  345.  
  346.     Most of the "interesting" programming techniques take place within the
  347. various subprograms which are a part of the three programs.  The three 
  348. Gadget subprograms and the GetIp subprogram are prime examples.  Further, 
  349. these subprograms have all been explained in some detail in previous issues
  350. of Amazing Computing. So, if you would like more information about these 
  351. subprograms, please refer back to the more recent issues of AC.
  352.  
  353.     Elsewhere, variations on the basic gadgets have also been employed; 
  354. and they all appear in the Review window!
  355.  
  356.     First, the area occupied by each record which is displayed is defined 
  357. as a gadget, but is never actually drawn.  This allows us to check for 
  358. "clicks" on individual records without having actual gadgets on the screen!
  359.  
  360.     Second, the scroll bar on the right side of the screen is really three 
  361. individual gadgets.  The top and bottom "arrow heads" are square gadgets 
  362. which are drawn with the interior and border in the background color (so 
  363. you can't see them).  Immediately following this, the triangles which you
  364. see are drawn independently by the main program, in white.   What this
  365. means is that you can really click anywhere in the square rather than just
  366. in the triangle!  The middle rectangle is a "normal" gadget with the white
  367. bar being superimposed on it, once again, by the main program. 
  368.  
  369.  The size of the white bar, in relation to the blue rectangle, represents 
  370. the number of records displayed, in relation to the total number of records
  371. in the file.  Further, the location of the white bar within the gadget 
  372. represents the location of the records displayed within the overall file. 
  373. To accomplish this, the GetGadget sets a global variable to the "y" value 
  374. of the mouse click.  The DrawBar subroutine then uses this value to
  375. determine exactly where to draw the white bar within the gadget.
  376.  
  377.     Thirdly, the inventory file itself is a relative file which is always 
  378. read from, or written to, via a relative record number. Since the number of
  379. records in the file is continually variable, the three programs need to be
  380. able to keep track of exactly how many records have been stored at any one
  381. time.  This is done by having a second file which contains a single record
  382. which indicates just how many records are in the main file.  This, in turn,
  383. makes it impossible to read beyond the end of the file.  When a record is
  384. deleted, a delete flag is set within the record. 
  385.  
  386. Thus, the record is still available, (and may be reinstated), until the 
  387. file is reorganized when the deleted record is actually removed from the 
  388. file.  If we didn't do this, we would have no alternative but to reorganize
  389. the file each time a record was deleted, and this is really not a very good
  390. idea, especially when the file starts to become fairly large!  The only
  391. other item of note in this area is that the count file is only updated when
  392. the "Add" function is terminated, or when the appropriate menu item is
  393. selected. Doing it after every record addition adds a tremendous amount of
  394. overhead and is simply not worth it.  This does open the door to allowing
  395. the count and data files to get out of step.  However, this should not
  396. happen very often, and if it should, the Update Count menu item of the File
  397. Maintenance Program will take care of it!
  398.  
  399.     Other than what we have just mentioned, the programs are really very 
  400. straightforward, and a little time spent studying the listings should 
  401. provide a complete understanding of how the programs works.
  402.  
  403.     Some Final Comments 
  404.     
  405.     If you have been looking for a sound, automated method of storing your
  406. household inventory for insurance purposes; or if after reading this
  407. article, it sounds like a good idea, I'm sure you'll find these three
  408. programs very useful.  Further, if you are at all interested in Basic
  409. programming, studying these programs should also prove to be very
  410. educational.
  411.     
  412.     As I'm sure you can see, a substantial amount of time and effort went 
  413. into developing these three programs, and for that reason I would ask that
  414. you do not modify the title screen in any shape or fashion.  Thank you, and
  415. enjoy!
  416.  
  417.     P.S.  This system was written and tested using the version of
  418. AmigaBasic which accompanies Workbench 1.1.  As of this writing, I have
  419. only just received my copy of Workbench 1.2, and while all  three programs
  420. appear to function correctly, no exhaustive testing under 1.2 has been
  421. performed. However, it does appears that AmigaBasic 1.2 uses a little more
  422. memory than the previous version.  This, in turn, means that memory
  423. sensitive programs (such as the main program here), become even more
  424. sensitive. Just beware!
  425.  
  426.  
  427.